<?php
$this->pageTitle = 'Thông tin thành viên ' . $courseActive->name . ' [ ' . $member->fullname. ' ]' ;
$this->breadcrumbs = array(
	'Thành viên' => array('index'),
	$member->fullname => array(),
	'Thông tin thành viên ' . $courseActive->name,
);
?>
<div class="heading">
    <h1><img src="<?php echo Util::themeUrl() ?>/images/header.ico" /><?php echo $this->pageTitle;?></h1>
    <div class="controls">
        <?php
        if (isset($_GET['ajax'])) {
            echo CHtml::button('Cập nhật', array('class' => 'controls', 'onclick' => "location.href='" . $this->createUrl('update', array('id' => $member->user_id, 'ajax' => true)) . "'"));
            echo CHtml::ajaxButton('Xóa', array('delete', 'ajax' => true), array(
                'type' 		=> 'post',
                'data' 		=> "chk[]={$member->user_id}",
                'success' 	=> 'function(data){$(".controls").hide(); $(".content").html(data);}'
            ), array('class' => 'controls', 'confirm'=> 'Bạn có chắc chắn xóa dữ liệu này?'));
        } else {
            echo CHtml::link('Cập nhật', array('update', 'id' => $member->user_id), array('class' => 'controls'));
            echo CHtml::link('Xóa', array('delete'), array(
                'class' => 'controls',
                'submit' => array('delete'),
                'confirm'=> 'Bạn có chắc chắn xóa dữ liệu này?',
                'params' => array('chk[]' => $member->user_id),
                'ajax' => array('type' => 'post')
            ));
        }
     ?>
    </div>
</div>

<div class="content">
	<div class="user-profile">
		<table cellpadding="0" cellspacing="0" width="100%">
			<tbody>
				<tr valign="top">
					<td width="75%" class="left-column">
						<div id="businessCardView" class="sliding-panel business-card showing-panel">
							<div class="border-grprofile"><?php echo CHtml::image(Util::getImageExist("profile", $member->avatar), "avatar",  array("class" =>"grprofile"));?></div>
							<h2>
								<?php echo CHtml::image(Util::getImageExist("avatar", (($member->sex == SEX_BOY) ? ICONBOY : ICONGIRL)), "avatar",  array('title' => (($member->sex == SEX_BOY) ? TITLE_BOY : TITLE_GIRL)));?>
								<?php echo CHtml::encode(Util::formatFullName($member->fullname));?>
							</h2>
							<?php $age = CHtml::encode(Util::getAge($member->birthday));?>
							<sub><?php echo ($age != '') ? ('(' . $age . ' tuổi)') : null;?></sub>
							<div>
								<table>
									<tr>
										<td><strong><?php echo CHtml::encode($member->getAttributeLabel('cmnd'))?></strong></td>
										<td><b><?php echo CHtml::encode($member->cmnd);?></b></td>
									</tr>
									<tr>
										<td><strong><?php echo CHtml::encode($member->getAttributeLabel('birthday'))?></strong></td>
										<td><?php echo CHtml::encode($member->birthday);?></td>
									</tr>
									<tr>
										<td><strong><?php echo CHtml::encode($member->getAttributeLabel('birthplace'))?></strong></td>
										<td><?php echo CHtml::encode($member->birthplace);?></td>
									</tr>
									<tr>
										<td><strong><?php echo CHtml::encode($member->getAttributeLabel('phone'))?></strong></td>
										<td><?php echo CHtml::encode(Util::formatPhone($member->phone));?></td>
									</tr>
									<tr>
										<td><strong><?php echo CHtml::encode($member->getAttributeLabel('cellphone'))?></strong></td>
										<td><?php echo CHtml::encode(Util::formatPhone($member->cellphone));?></td>
									</tr>
									<tr>
										<td><strong><?php echo CHtml::encode($member->getAttributeLabel('email'))?></strong></td>
										<td><?php echo CHtml::encode($member->email);?></td>
									</tr>
									<tr>
										<td><strong><?php echo CHtml::encode($member->getAttributeLabel('address'))?></strong></td>
										<td><?php echo CHtml::encode($member->address);?></td>
									</tr>
									<tr>
										<td><strong><?php echo CHtml::encode($member->getAttributeLabel('contact_address'))?></strong></td>
										<td><?php echo CHtml::encode($member->contact_address);?></td>
									</tr>
									<?php if (isset($courseActive)) :?>
									<tr>
										<td><strong><?php echo CHtml::encode($courseActive->getAttributeLabel('id'))?></strong></td>
										<td><code class="studentship"><?php echo CHtml::encode($courseActive->id);?></code></td>
									</tr>
									<?php endif;?>
								</table>
							</div>
						</div>
					</td>
					<td align="right" class="right-column" style="vertical-align: top">
						<table>
							<tr>
								<td><?php echo CHtml::encode($account->getAttributeLabel('username'));?></td>
								<td class="ta-left">
									<div class="legendColorBox"  style="width: 54px;">
										<div class="legendColor" style="background: #8ec657; width: 50px; text-align: center;">
											<?php echo CHtml::encode($account->username);?></div>
									</div>
								</td>
							</tr>
							<tr>
								<td><?php echo CHtml::encode($account->getAttributeLabel('status'));?></td>
								<td class="ta-left"><?php echo CHtml::encode(Util::itemAlias('UserStatus', $account->status));?></td>
							</tr>
							<tr>
								<td><?php echo CHtml::encode($account->getAttributeLabel('create_at'));?></td>
								<td class="ta-left"><?php echo CHtml::encode(Util::formatTime($account->create_at, true, '-'));?></td>
							</tr>
							<tr>
								<td><?php echo CHtml::encode($account->getAttributeLabel('lastvisit_at'));?></td>
								<td class="ta-left"><?php echo CHtml::encode(Util::formatTime($account->lastvisit_at, true, '-', true));?></td>
							</tr>
						</table>
					</td>
				</tr>
			</tbody>
		</table>
		<div class="fieldset-none fieldtype-icon1">
		<?php $this->beginWidget('ext.coolfieldset.JCollapsibleFieldset', array(
					        'legend'=> $member->getAttributeLabel('social_position')
					    )); ?>
					    <?php echo nl2br(CHtml::encode($member->social_position));?>
		<?php $this->endWidget(); ?>
		</div>
		<br/>
		<div class="fieldset-none fieldtype-icon1">
		<?php $this->beginWidget('ext.coolfieldset.JCollapsibleFieldset', array(
					        'legend'=> $member->getAttributeLabel('social_activity')
					    )); ?>
					    <?php echo nl2br(CHtml::encode($member->social_activity));?>
		<?php $this->endWidget(); ?>
		</div>
	</div>
	<div class="clear"></div>
	<div class="user-profile">
		<h1 class="header-scholarship">Thông tin ân nhân</h1>
		<table class="education-info">
			<tr>
				<td align="right"><strong><?php echo CHtml::encode($member->getAttributeLabel('donor_name'));?></strong></td>
				<td class=""><?php echo CHtml::encode($member->donor_name);?></td>
			</tr>
			<tr>
				<td align="right"><strong><?php echo CHtml::encode($member->getAttributeLabel('donor_email'));?></strong></td>
				<td class=""><?php echo CHtml::encode($member->donor_email)?></td>
			</tr>
			<tr>
				<td align="right"><strong><?php echo CHtml::encode($member->getAttributeLabel('donor_address'));?></strong></td>
				<td class=""><?php echo CHtml::encode($member->donor_address)?></td>
			</tr>
		</table>
	</div>
	<div class="clear"></div>
	<div class="user-profile">
		<h1 class="header-scholarship">Bảng tóm tắt hoạt động tại CLB</h1>
		<table cellpadding="0" cellspacing="0" width="100%">
			<tbody>
				<tr valign="top">
					<td width="300px;" class="left-column" style="vertical-align: top">
					<?php $form=$this->beginWidget('CActiveForm', array(
						'id'=>'statistic-excel-form',
						'enableAjaxValidation'=>false,
						'action' => array('downloadExcel')
					)); ?>
						<div class="seachDate">
							Từ
								<?php echo CHtml::textField('Statistic[start_year]','',array('id' => 'start_year', 'class'=> 'picker-monthyear')); ?>
							đến
								<?php echo CHtml::textField('Statistic[end_year]','',array('id' => 'end_year', 'class'=> 'picker-monthyear')); ?>
								<?php echo CHtml::button('Thống kê', array('id' => 'statistic', 'class' => 'button'));?>
								<?php echo CHtml::hiddenField('user_id', $member->user_id);?>
						</div>
						 <div class = "statistic-excel">
				        	 <?php echo CHtml::imageButton(Util::themeUrl() . '/images/download_icon.png', array('id' => 'downloadExcel', 'class' => 'button-excel btn'));?>
				        </div>
				        <?php $this->endWidget(); ?>
				        <div class="clear"></div>
						<table class="table-bordered">
				          <tbody>
				            <tr>
				              <td>Số lần gửi thư thăm hỏi ân nhân</td>
				              <td width="20px;" class="td-number">
									<strong>2</strong>
				              </td>
				            </tr>
				            <tr>
				              <td>Số lần được mời sinh hoạt</td>
				               <td class="td-number">
									<strong id="statistic-asigned"><?php echo $statistic['asigned'];?></strong>
				              </td>
				            </tr>
				            <tr>
				              <td>Số lần tham gia</td>
				             <td class="td-number">
									<strong  id="statistic-joined"><?php echo $statistic['joined'];?></strong>
				              </td>
				            </tr>
				            <tr>
				              <td>Số lần không tham gia</td>
				              <td class="td-number">
									<strong  id="statistic-absence"><?php echo $statistic['absence'];?></strong>
				              </td>
				            </tr>
				          </tbody>
				        </table>
					</td>
					<td class="right-column fieldset-none" style="vertical-align: top">
						<div class = "div-fieldset">
						<?php $this->beginWidget('ext.coolfieldset.JCollapsibleFieldset', array(
					        'legend'=>'Chi tiết các buổi tham dự'
					    )); ?>
					    	<?php if (isset($announcements)) :?>
							<ul id = 'announcements-list'>
								<?php foreach($announcements as $announcement) : ?>
								<li><span><?php echo CHtml::encode($announcement->title);?></span></li>
								<?php endforeach;?>
							</ul>
							<?php endif; ?>
						<?php $this->endWidget(); ?>
						</div>
					</td>
				</tr>
			</tbody>
		</table>
	</div>
	<div class="user-profile">
		<h1 class="header-scholarship">Bảng thành tích học tập</h1>
		<?php if (isset($edutionActive)) :?>
		<table cellpadding="0" cellspacing="0" width="100%">
			<tbody>
				<tr valign="top">
					<td width="50px;" class="left-column" style="vertical-align: top">
						<div class="legendBox">
							<table cellspacing="2" cellpadding="3">
								<tbody>
								<tr class="legendSelect" id="<?php echo $edutionActive->id?>">
									<td><span id="select-icon-<?php echo $edutionActive->id?>" class="select-icon legendColorBox-current">&nbsp;&nbsp;</span></td>
									<td>
										<div class="legendColorBox">
											<div class="legendColor" style="background: <?php echo $logEducationColor[0];?>"><?php echo $edutionActive->code_id;?></div>
										</div>
									</td>
								</tr>
								<?php if (!empty($edutionTrash)) : foreach ($edutionTrash as $education): $i = 1;?>
								<tr class="legendSelect" id="<?php echo $education->id?>">
									<td><span id="select-icon-<?php echo $education->id?>" class="select-icon">&nbsp;&nbsp;</span></td>
									<td>
										<div class="legendColorBox">
											<div class="legendColor" style="background: <?php echo $logEducationColor[$i];?>"><?php echo $education->code_id;?></div>
										</div>
									</td>
								</tr>
								<?php $i++;endforeach;endif;?>
							</tbody>
						</table>
					</div>
					</td>
					<td class="right-column fieldset-none" style="vertical-align: top">
						<?php $this->widget('SemesterView', array('education' => $edutionActive, 'current' => true)); ?>
						<?php if (!empty($edutionTrash)) : foreach ($edutionTrash as $education):;?>
							<?php $this->widget('SemesterView', array('education' => $education)); ?>
						<?php endforeach;endif;?>
					</td>
				</tr>
			</tbody>
		</table>
		<?php endif;?>
	</div>
</div>
<script  type="text/javascript">
    $(document).ready(function() {
        $('#statistic').live("click", function(){
        	waitingStatistic();
            var count=0;
            var params 	= 'YII_CSRF_TOKEN=<?php echo  Yii::app()->request->csrfToken; ?>';
            params += '&id=' + <?php echo $member->user_id?>;
            params += '&start=' + $('#start_year').val();
            params += '&end=' + $('#end_year').val();

            $.ajax({
                    type: "POST",
                    url: '<?php echo $this->createUrl('statistic', array('ajax' => true)) ?>',
                    data: params,
                    dataType: 'json',
                    success: function(data) {
                    	reloadStatistic(data);
                    } //success
                });//ajax
                return false;
        });
    });
    function reloadStatistic(data) {
    	$('#announcements-list').removeClass('waiting-list');
    	$.each( data['announcement'], function( key, value ) {
    		if (value != '')
    			$("#announcements-list").append("<li><span>" + value + "</span></li>");
    	});

    	$('#statistic-asigned').removeClass('waiting');
    	$('#statistic-asigned').text(data['asigned']);

    	$('#statistic-absence').removeClass('waiting');
    	$('#statistic-absence').text(data['absence']);

    	$('#statistic-joined').removeClass('waiting');
    	$('#statistic-joined').text(data['joined']);
    }
    function waitingStatistic() {
    	$('#announcements-list li').remove();
    	$('#announcements-list').addClass('waiting-list');

    	$('#statistic-asigned').text('');
    	$('#statistic-asigned').addClass('waiting');

    	$('#statistic-absence').text('');
    	$('#statistic-absence').addClass('waiting');

    	$('#statistic-joined').text('');
    	$('#statistic-joined').addClass('waiting');
    }
</script>